layui.use(['form', 'jquery', 'layer'], function () {
    var form = layui.form
        , layer = layui.layer
        , $ = layui.$;



    //自定义验证规则
    form.verify({
        userName: function (value) {
            if (value.length < 3) {
                return '用户名至少得3个字符啊';
            }
        }
        , pass: [
            /^[\S]{3,12}$/
            , '密码必须3到12位，且不能出现空格'
        ]
        , ip: [/(^$)|((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))).){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))/,
            '请输入正确的ip地址'],
        phone1:[/(^$)|^1\d{10}$/,'请输入正确的手机号'],
        email1:[/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,'邮箱格式不正确'],
        url1:[/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/,'链接格式不正确'],
        number1:[/(^$)|^\d+$/,'只能填写数字'],
        date1:[/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/,'日期格式不正确'],
        identity1:[/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/,'请输入正确的身份证号'],
        carNum:[/(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$)/
            ,'请输入正确的车牌号']
    });



    //监听提交
    form.on('submit(tijiao)', function(data){
        $.ajax({
            url:'/loginOrRegister/clientReg',
            dataType:'json',
            type:'POST',
            async: false,
            data: data.field,
            success: function(resp){
                if (resp.state==1){
                    location.href="/pages/LoginOrRegister/login.html";
                }else {
                    layer.msg("注册失败,该手机号已被注册");
                }
            },
            error:function(response){
                console.log(response);
            }
        });
        return false;
    });


})